package com.guaoran.headFirst.stategy;

import com.guaoran.headFirst.stategy.interfaces.FlyBehavior;
import com.guaoran.headFirst.stategy.interfaces.QuackBehavior;

/**
 * @author : 孤傲然
 * @Description :
 *  鸭子类
 *      1.将可能发生变化的进行封装
 *      2.针对接口编程，而不是针对接口实现
 *      3.多用组合，少用集成
 * @date :2018/3/26 22:20
 */
public abstract class Duck {
    public QuackBehavior quackBehavior;
    public FlyBehavior flyBehavior;
    public Duck(){}
    public Duck(QuackBehavior quackBehavior,FlyBehavior flyBehavior){
        this.quackBehavior = quackBehavior;
        this.flyBehavior = flyBehavior;
    }
    public abstract void display();
    //飞行方法
    public void performFly(){
        flyBehavior.fly();
    }
    //鸭子叫方法
    public void performQuack(){
        quackBehavior.quack();
    }
    public void eat(){
        System.out.println("is eat....");
    }

    public QuackBehavior getQuackBehavior() {
        return quackBehavior;
    }

    public void setQuackBehavior(QuackBehavior quackBehavior) {
        this.quackBehavior = quackBehavior;
    }

    public FlyBehavior getFlyBehavior() {
        return flyBehavior;
    }

    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
    }
}
